github pages的创建
1、安装Git
下载安装git
详细可见:如何在windows下安装GIT
2、注册github
注册你的username和邮箱,邮箱十分重要,GitHub上很多通知都是通过邮箱的。
注册过程比较简单,详细也可以看:创建GitHub账号
###3、使用GitHub Pages建立博客
与GitHub建立好链接之后,就可以方便的使用它提供的Pages服务,GitHub Pages分两种,一种是你的GitHub用户名建立的username.github.com这样的用户&组织页(站),另一种是依附项目的pages。
第一种方式:User & Organization Pages
想建立个人博客是用的第一种,形如beiyuu.github.com这样的可访问的站,每个用户名下面只能建立一个,创建之后点击Admin进入项目管理,可以看到是这样的: 而普通的项目是这样的,即使你也是用的othername.github.com:
创建好username.github.com项目之后,提交一个index.html文件,然后push到GitHub的master分支(也就是普通意义上的主干)。第一次页面生效需要一些时间,大概10分钟左右。
生效之后,访问username.github.com就可以看到你上传的页面了,beiyuu.github.com就是一个例子。第二种方式:
关于第二种项目gh-pages,简单提一下,他和用户pages使用的后台程序是同一套,只不过它的目的是项目的帮助文档等跟项目绑定的内容,所以需要在项目的gh-pages分支上去提交相应的文件,GitHub会自动帮你生成项目pages。
注意:一开始我使用了第二种来建立博客,但是将Hexo上传上去后,访问后只显示html,不能加载js和css样式。也不知道是什么原因。后来在github上用第一种方式又建了一个仓库,上传上去后访问,显示也正常了。
创建第一种方式的关键在于:仓库名称必须为username.github.com (注意不是github.io)
创建步骤如下:
1、新建仓库
2、创建成功后,进入资源-setting
3、overwrite 单击最下面的按钮launch automatic pages generator。
4、选择主题并发布
5、过十分钟就可以访问username.github.com来查看新建的github-pages了。
上传hexo
github pages的创建完成了,接下来就是上传Hexo了
1、配置_config.yml
重点是最后# Deployment的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 # Hexo Configuration
## Docs: http://zespia.tw/hexo/docs/configure.html
## Source: https://github.com/tommy351/hexo/
# Site 这里的配置,哪项配置反映在哪里,可以参考我的博客
title: Zippera's blog #站点名,站点左上角
subtitle: Walk steps step by step #副标题,站点左上角
description: Walk steps step by step #给搜索引擎看的,对站点的描述,可以自定义
author: zippera #在站点左下角可以看到
email: #你的联系邮箱
language: zh-CN #中国人嘛,用中文
# URL #这项暂不配置,绑定域名后,欲创建sitemap.xml需要配置该项
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://zipperary.com
root: /
permalink: :year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: categories
# Writing 文章布局、写作格式的定义,不修改
new_post_name: :title.md # File name of new posts
default_layout: post
auto_spacing: false # Add spaces between asian characters and western characters
titlecase: false # Transform title into titlecase
max_open_file: 100
filename_case: 0
highlight:
enable: true
backtick_code_block: true
line_number: true
tab_replace:
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Archives 默认值为2,这里都修改为1,相应页面就只会列出标题,而非全文
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 1
category: 1
tag: 1
# Server 不修改
## Hexo uses Connect as a server
## You can customize the logger format as defined in
## http://www.senchalabs.org/connect/logger.html
port: 4000
logger: false
logger_format:
# Date / Time format 日期格式,不修改
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: MMM D YYYY
time_format: H:mm:ss
# Pagination 每页显示文章数,可以自定义,我将10改成了5
## Set per_page to 0 to disable pagination
per_page: 5
pagination_dir: page
# Disqus Disqus插件,我们会替换成“多说”,不修改
disqus_shortname:
# Extensions 这里配置站点所用主题和插件,暂默认,后面会介绍怎么修改
## Plugins: https://github.com/tommy351/hexo/wiki/Plugins
## Themes: https://github.com/tommy351/hexo/wiki/Themes
theme: light
exclude_generator:
plugins:
- hexo-generator-feed
- hexo-generator-sitemap
# Deployment Hexo部署到github要配置,注意repository是ssh格式的
## Docs: http://zespia.tw/hexo/docs/deploy.html
deploy:
type: git
repository: git@github.com:username/username.github.com.git
branch: master
2、部署上传
在博客目录下,使用命令生成静态文本,每次修改后,上传前都需要再生成1
$ hexo generate
使用命令上传到github1
$ hexo deploy
这一步可能出现很多错误
错误总结:
1、出现错误 Error:spawn git ENOENT
原因:没有git支持。
解决方法:在博客目录下,使用git bash来运行hexo deploy命令。
2、在git bash上出现错误:Not a git repository (or any of the parent directories)
原因:没有生成本地git仓库。
解决方法:在博客目录下的.deploy_git文件夹中使用命令创建并添加所有文件到仓库1
2$ git init
$ git add .
错误解决后再使用hexo deploy命令上传。
在deploy命令执行完后,上github上的仓库中。查看是否上传成功。
过几分钟访问github-pages看博客是否生成成功。
#最后
如果大家在创建的时候碰到什么问题,可以留言。我会尽量解答。